package com.shen;

import org.junit.Test;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Author:shen
 * CreateDate:2020/5/31.
 * Function:
 */
public class MyTest {
    /**
     * ArrayList:基于动态数组结构，访问和末尾添方便，主要是get()set()方便，删除和中间添加不方便，要移动数组
     * LinkList：基于链表结构，查询不方便，他会全都查一遍，要移动指针，添加和删除方便
     *
     */
    public  static long startTime;
    public  static long stopTime;
    public static void main(String[] args) {

        ArrayList arrayList=new ArrayList();
        LinkedList linkedList=new LinkedList();

       /* ListGetAndAndTest(arrayList,10000);*/
        //list add test:3
        //list get test:4
        //list remove test:12
        ListGetAndAndTest(linkedList,10000);
        //list add test:3
        //list get test:113
       // list remove test:51

    }

    public static void ListGetAndAndTest(List list,int size){

         startTime = System.currentTimeMillis();//记录开始的时间
        for (int i=0;i<size;i++){
            list.add(i);
        }
         stopTime = System.currentTimeMillis();//记录开始的时间

        System.out.println(list+"list add test:"+(stopTime-startTime));

        startTime=System.currentTimeMillis();

        for (int i=0;i<list.size();i++){
            list.get(i);
        }
        stopTime=System.currentTimeMillis();

        System.out.println(list+"list get test:"+(stopTime-startTime));

        startTime=System.currentTimeMillis();

        for (int i=0;i<list.size();i++){
            list.remove(i);
        }
        stopTime=System.currentTimeMillis();

        System.out.println(list+"list remove test:"+(stopTime-startTime));
    }


}
